﻿<local:MapLayer x:Class="TilegroupLayer"
                x:Name="TilegroupLayer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WPFZ80MapEditor"
             xmlns:converters="clr-namespace:WPFZ80MapEditor.ValueConverters"
             mc:Ignorable="d" 
                MouseLeftButtonDown="ObjectCanvas_MouseLeftButtonDown"
                  MouseLeftButtonUp="ObjectCanvas_MouseLeftButtonUp" MouseMove="ObjectCanvas_MouseMove"
             Width="256" Height="256" Focusable="True" KeyDown="TilegroupLayer_KeyDown_1" LayerType="TilegroupLayer">
    <local:MapLayer.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ColorsAndStoryboards.xaml" />
            </ResourceDictionary.MergedDictionaries>
            
            <converters:DashedStrokeConverter x:Key="DashedStrokeConverter"/>
            <local:SegmentConverter x:Key="SegmentConverter"/>
        </ResourceDictionary>
    </local:MapLayer.Resources>

    <UserControl.CommandBindings>
        <CommandBinding x:Name="Copy" Command="Copy"
                        CanExecute="Copy_CanExecute"
                        Executed="Copy_Executed"/>
    </UserControl.CommandBindings>
    <Canvas x:Name="ObjectCanvas" Width="256" Height="256" Background="Transparent" ClipToBounds="True" >
        <Path x:Name="TilegroupSelectionShape" DataContext="{Binding TilegroupSelection, ElementName=TilegroupLayer}"
                      Canvas.Left="{Binding MapOffset.X}"
                      Canvas.Top="{Binding MapOffset.Y}"
                      Stroke="{StaticResource SelectionBrush}"
              Fill="Transparent"
              StrokeDashArray="{Binding Floating, ElementName=TilegroupLayer, Converter={StaticResource DashedStrokeConverter}}"
              StrokeThickness="2" Cursor="SizeAll"
                  MouseLeftButtonDown="TilegroupSelectionShape_MouseLeftButtonDown"
                  MouseLeftButtonUp="TilegroupSelectionShape_MouseLeftButtonUp"
                  MouseMove="TilegroupSelectionShape_MouseMove"
                  >
            <Path.Style>
                <Style TargetType="Path">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Active, ElementName=TilegroupLayer}" Value="False">
                            <Setter Property="Opacity" Value="0"/>
                        </DataTrigger>
                    </Style.Triggers>
                    <Setter Property="Opacity" Value="1.0"/>
                </Style>
            </Path.Style>
            <Path.Data>
                <PathGeometry>
                    <PathGeometry.Figures>
                        <PathFigureCollection>
                            <PathFigure IsClosed="True" StartPoint="{Binding Path=Vertices[0]}"
                                                Segments="{Binding Path=Vertices, Converter={StaticResource SegmentConverter}}">
                            </PathFigure>
                        </PathFigureCollection>
                    </PathGeometry.Figures>
                </PathGeometry>
            </Path.Data>
        </Path>
        <Border Name="SelectionRect" BorderBrush="{StaticResource SelectionBrush}" BorderThickness="1" Height="150" Width="150" Canvas.Left="10" Canvas.Top="50" Visibility="Hidden">
            <Border.Background>
                <SolidColorBrush Color="{Binding Color, Source={StaticResource SelectionBrush}}" Opacity="0.4"/>
            </Border.Background>
        </Border>
    </Canvas>
</local:MapLayer>
